﻿using System.Windows.Controls;
using System.Windows.Media;

namespace nRoute.Samples.FutureDesktop.Behaviors
{
    public class BorderHoverBehavior
        : HoverBehaviorBase<Border>
    {
        private Brush _border;
        private Brush _background;
        
#region Properties

        public Brush HoverBorder
        {
            get { return (Brush)GetValue(HoverBorderProperty); }
            set { SetValue(HoverBorderProperty, value); }
        }

        public Brush HoverBackground
        {
            get { return (Brush)GetValue(HoverBackgroundProperty); }
            set { SetValue(HoverBackgroundProperty, value); }
        }

#endregion

#region Overrides

        protected override void OnHighlight()
        {
            if (this.HoverBorder != null)
            {
                _border = this.AssociatedObject.BorderBrush;
                this.AssociatedObject.BorderBrush = this.HoverBorder;
            }
            if (this.HoverBackground != null)
            {
                _background = this.AssociatedObject.Background;
                this.AssociatedObject.Background = this.HoverBackground;
            }
        }

        protected override void OnUnHighlight()
        {
            if (this.HoverBorder != null)
            {
                this.AssociatedObject.BorderBrush = _border;
                _border = null;
            }
            if (this.HoverBackground != null)
            {
                this.AssociatedObject.Background = _background;
                _background = null;
            }
        }

#endregion

    }
}
